<template>
  <div style="width:100%;height:100%">
    <v-chart :options="option" :initOptions="initOptions" :theme="theme" autoresize />
  </div>
</template>
<script>

export default {
  name: 'chart',
  props: ['index'],
  mounted () {
  },
  data () {
    return {
      initOptions: { renderer: 'canvas' },
      theme: 'default'
    }
  },
  methods: {
  },
  computed: {
    insideSlideArray () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent
    },
    insideArrayIndex () {
      return this.insideSlideArray.indexOf(this.insideSlideArray.filter((currentValue) => {
        return currentValue.i === this.index
      })[0])
    },
    getDetail () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent[this.insideArrayIndex].itemContent.detail
    },
    getData () {
      var data = []
      for (let i = 1, nr = this.getDetail.nr; i < nr; i++) {
        if (this.getDetail.sheetData[i][0]) {
          data.push({
          name: this.getDetail.sheetData[i][0],
          depth: this.getDetail.sheetData[i][1],
          value: this.getDetail.sheetData[i][2]
        })
        }
      }
      return data
    },
    getLinks () {
      var links = []
      for (let i = 1, nr = this.getDetail.nr; i < nr; i++) {
        links.push({
          source: this.getDetail.sheetData[i][3],
          target: this.getDetail.sheetData[i][4],
          value: this.getDetail.sheetData[i][5]
        })
      }
      return links
    },
    option () {
      return {
        animation: this.getDetail.animation,
        title: this.getDetail.title,
        tooltip: {},
        color: this.getDetail.color[this.getDetail.color.option],
        backgroundColor: this.getDetail.backgroundColor[this.getDetail.backgroundColor.option],
        series: [
          {
            type: 'sankey',
            data: this.getData,
            links: this.getLinks,
            ...this.getDetail.simpleSankey
          }]
      }
    }
  }
}
</script>
<style scoped>
  .echarts {
    width: 100%;
    height: 100%;
  }
</style>
<style>

</style>
